﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using WMSABL;
using WMSABL.SY;
using WMSAML.SY;
using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;
using SYDZ.WMS.DBUtility;

namespace ElectronicWMSA.Warehouse
{
    public partial class Frm_WWC : Form
    {
        private string strWhere = "";
        public Frm_WWC()
        {
            InitializeComponent();
        
            this.page1.PageCurrent = 1;
            this.page1.PageSize = 5000;
            this.page1.Bind();
        }
        private int DBindData()
        {
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "T_TemRuStock";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.page1.PageCurrent;
            pageData.PageSize = this.page1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            this.page1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.page1.bindingNavigator.BindingSource = page1.bindingSource;
            this.dataGridView2.AutoGenerateColumns = false;
            this.dataGridView2.DataSource = this.page1.bindingSource;
            this.dataGridView2.ClearSelection();
            this.dataGridView2.CurrentCell = null;
            return pageData.TotalCount;
        }
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindData();
        }
        private void dataGridViewUserList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridView2.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView2.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        private void btnUserSearch_Click(object sender, EventArgs e)
        {
           // if (!SystemVariable.VaildationPermission("查询")) return;

            this.strWhere = " 1=1 ";
          
            if (!string.IsNullOrEmpty(txt_KW.Text.Trim()))
            {
                strWhere += "  and Posiont1 like '%" + txt_KW.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_Machine.Text.Trim()))
            {
                strWhere += "  and Replace(Product_Model,' ','') like '%" + txt_Machine.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_DH.Text.Trim()))
            {
                strWhere += "  and PutList_NO like '%" + txt_Machine.Text.Trim() + "%'";
            }
        

            this.page1.Bind();
        }
        #region 
        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }
        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }
        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }
        #endregion
        #region 导出
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_exct_Click(object sender, EventArgs e)
        {
            List<string> list = new List<string>();
            if (!string.IsNullOrEmpty(txt_DH.Text.Trim()))
            {
                string SQL = "UPdate dbo.T_TemRuStock set [Posiont1]='"+txt_DH.Text.Trim().ToUpper()+"'  where " + strWhere;
                list.Add(SQL);
                string sqlpre = "UPdate dbo.T_StockPrepare  set [Posiont1]='" + txt_DH.Text.Trim().ToUpper() + "'  where " + strWhere;
                list.Add(sqlpre);
                if (DbHelperSQL.ExecuteSqlTran(list) == 0)
                {
                    //MessageBox.Show("追加失败");
                }
                else
                {
                    string TSQL = "  select  *    from  T_TemRuStock where  " + strWhere;
                    DataTable dt = DbHelperSQL.ExecuteDataTable(TSQL);
                    foreach (DataRow dr in dt.Rows)
                    {
                        string sqlStock = " select  * from  T_Stock where  Product_Model='"+dr["Product_Model"].ToString()+"'  and  Serial_Number='"+dr["Serial_Number"].ToString()+"'";
                        DataTable dtt = DbHelperSQL.ExecuteDataTable(sqlStock);
                        if (dtt.Rows.Count>0)
                        {
                            //string sql="";
                            //     INSERT INTO [T_Stock] ([PutList_NO] ,[List_NOType] ,[Product_Model] ,[Serial_Number] , ");
                            //      [Update_Time] ,[Update_UserID] ,[BK01] ,[BK03],bk06,Posiont1) VALUES ( "'" + spModel.PutList_NO + "','" + spModel.List_NOType + "','" + spModel.Product_Model + "','");
                            //        sb.Append(spModel.Serial_Number + "','" + spModel.Update_Time + "','" + PublicBLL.UserID + "','" + spModel.BK01 + "','" + RuKuType + "','1','" + txt_KW_NO.Text.ToUpper().ToString() + "')");
                            //        list.Add(ab.ToString());
                        }
                    }
                    List<string> list1 = new List<string>();
                    
                   
                }
            }
         
        }
        #endregion
    }
}
